package Common

type PageParam[T any] struct {
	Size             int64
	Current          int64
	Records          []T
	Total            int64
	SearchCount      bool
	CountId          string
	MaxLimit         int64
	OptimizeCountSql bool
}

func (p *PageParam[T]) GetRecords() []T {
	return p.Records
}

func (p *PageParam[T]) SetRecords(records []T) *PageParam[T] {
	p.Records = records
	return p
}

func (p *PageParam[T]) GetTotal() int64 {
	return p.Total
}

func (p *PageParam[T]) SetTotal(total int64) *PageParam[T] {
	p.Total = total
	return p
}

func (p *PageParam[T]) GetSearchCount() bool {
	if p.Total < 0 {
		return false
	}
	return p.SearchCount
}

func (p *PageParam[T]) SetSearchCount(isSearchCount bool) *PageParam[T] {
	p.SearchCount = isSearchCount
	return p
}

func (p *PageParam[T]) GetSize() int64 {
	return p.Size
}

func (p *PageParam[T]) SetSize(size int64) *PageParam[T] {
	maxSize := int64(100)
	if size > maxSize {
		p.Size = maxSize
	} else {
		p.Size = size
	}
	return p
}

func (p *PageParam[T]) GetCurrent() int64 {
	return p.Current
}

func (p *PageParam[T]) SetCurrent(current int64) *PageParam[T] {
	p.Current = current
	return p
}
